package com.qhx.backme.handler;

import cn.hutool.json.JSONUtil;
import com.qhx.backme.exception.SupplyChainException;
import com.qhx.backme.exception.WeBaseFrontException;
import com.qhx.backme.model.Result;
import com.qhx.backme.model.vo.ResultVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 全局异常处理器
 *
 * @author: qhx20040819
 * @date: 2023-10-23 21:58
 **/

/**
 * 全局异常处理器
 *
 * @author: qhx20040819
 * @date: 2023-10-20 16:19
 **/
@ControllerAdvice
@ResponseBody // 没加responseBody,毕竟我觉得是swagger获得数据并解析渲染,要求必须是json,但是我们返回了对象。
@Slf4j
public class GlobalExceptionHandler
{

    @ExceptionHandler(WeBaseFrontException.class)
    public Result handlerWebaseFrontException(WeBaseFrontException excepxtion)
    {
        log.error("webase-front exception:" , excepxtion);
        return Result.error(excepxtion.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public Result handlerException(Exception excepxtion)
    {
        log.error("Exception",excepxtion);
        return Result.error(excepxtion.getMessage());
    }
}